// These are meant to be typed into the REPL. You can also run
// scala -Xnojline < repl-session.scala to run them all at once.

val prices = List(5.0, 20.0, 9.95)
val quantities = List(10, 2, 1)

prices zip quantities
//res90: List[(Double, Int)] = List((5.0,10), (20.0,2), (9.95,1))

// 拉链后执行map操作
(prices zip quantities) map { p => p._1 * p._2 }
//res91: List[Double] = List(50.0, 40.0, 9.95)

((prices zip quantities) map { p => p._1 * p._2 }) sum
//res92: Double = 99.95

List(5.0, 20.0, 9.95) zip List(10, 2)
//res93: List[(Double, Int)] = List((5.0,10), (20.0,2))

// 如果一个元素数量比较少，则用默认值代替
List(5.0, 20.0, 9.95).zipAll(List(10, 2), 0.0, 1)
//res94: List[(Double, Int)] = List((5.0,10), (20.0,2), (9.95,1))

List(5.0).zipAll(List(10, 2), 0.0, 1)
//res95: List[(Double, Int)] = List((5.0,10), (0.0,2))

// 和索引值序列进行拉链操作
"Scala".zipWithIndex
//res96: scala.collection.immutable.IndexedSeq[(Char, Int)] = Vector((S,0), (c,1), (a,2), (l,3), (a,4))

"Scala".zipWithIndex.max
//res97: (Char, Int) = (l,3)

"Scala".zipWithIndex.max._2
//res98: Int = 3

//unzip函数可以将一个元组的列表转变成一个列表的元组
"Scala".zipWithIndex.unzip
//res99: (scala.collection.immutable.IndexedSeq[Char], scala.collection.immutable.IndexedSeq[Int]) = (Vector(S, c, a, l, a),Vector(0, 1, 2, 3, 4))


"Scala".zipWithIndex.unzip._1
//res100: scala.collection.immutable.IndexedSeq[Char] = Vector(S, c, a, l, a)

"Scala".zipWithIndex.unzip._2
//res101: scala.collection.immutable.IndexedSeq[Int] = Vector(0, 1, 2, 3, 4)